package com.wechat.scheme.controller.admin;

import com.wechat.scheme.controller.BaseCtrl;
import com.wechat.scheme.entity.SchemeUser;
import com.wechat.scheme.entity.WxButton;
import com.wechat.scheme.entity.model.MenuSearchMo;
import com.wechat.scheme.entity.model.WxButtonMo;
import com.wechat.scheme.response.Response;
import com.wechat.scheme.service.WxButtonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/admin/menu")
public class SchemMenuCtrl extends BaseCtrl {

    @Autowired
    WxButtonService buttonService;

    @PostMapping("/list")
    public Response list(@RequestBody MenuSearchMo mo){
        SchemeUser schemeUser = getUser();
       List<WxButton> buttonList = buttonService.findBt(mo.getAppId());
        return Response.succeed(buttonList);
    }

    @GetMapping("/del/{id}")
    public Response del(@PathVariable String id){
        buttonService.delBt(id);
        return Response.succeed();
    }

    @PostMapping("/put")
    public Response put(HttpServletRequest request,@RequestBody WxButtonMo wxButton){
        wxButton.setSourceAppId(getAppId(request));
        buttonService.saveBt(wxButton);
        return Response.succeed();
    }

    @PostMapping("/listMenu")
    public Response listMenu(@RequestBody MenuSearchMo mo){
        SchemeUser schemeUser = getUser();
        List<WxButton> buttonList = buttonService.findBt(mo.getAppId());
        return Response.succeed(buttonList);
    }


}
